import { Toast } from "vant";

export const myMixins = {
  data () {
    return {
      sharetitle: '活动宝',
      share_describe: '商户引流，增加客源，助力产品推广',
      shareimg: 'https://www.umiyun.net/addons/youmi_activitys/public/uploads/c1bab710a6db68e7f308653929d9c460.jpg'
    }
  },
  methods: {
	  
    toDetailView(item,fromView) {
		  console.log(item)
    	if(item.course.type==2){
    		this.$router.push(`/course/detail4xx?id=${item.course.id}&course_id=${item.course.id}&type=${item.course.type}&fromView=${fromView}`)
    	}else{
    		this.$router.push(`/course/detail4xs?id=${item.course.id}&course_id=${item.course.id}&type=${item.course.type}&fromView=${fromView}`)
    	}
    },
    toView(path){
    	this.$router.push(path)
    },
    configItemShare() {
      const _this = this;
      let params = {}
      _this.$request.configItemShare(params).then(res=>{
        if(res.ret == 200){
          _this.sharetitle = res.data.value.sharetitle
          _this.share_describe = res.data.value.share_describe
          _this.shareimg = res.data.value.shareimg
          _this.shareInit()
        }else{
          Toast('configJssdk error')
        }
      })
    },
    shareInit() {
      const _this = this;
      const url = (location.href.split('#')[0])
      let params = {
          url: url
      }
      _this.$request.configJssdk(params).then(res=>{
        if(res.ret == 200) {
          wx.config({
            debug: false,// 是否开启调试模式
            appId: res.data.appId,//appid
            timestamp: res.data.timestamp,// 时间戳
            nonceStr: res.data.nonceStr,// 随机字符串
            signature: res.data.signature,// 签名
            jsApiList: ['checkJsApi', 'updateAppMessageShareData', 'updateTimelineShareData']// 需要使用的JS接口列表
          })
          const dataShare = { 
            title: _this.sharetitle,
            desc: _this.share_describe, // 分享描述
            link: "https://www.umiyun.net/addons/youmi_activitys/public/mobile/index.html", // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: _this.shareimg, // 分享图标
            success: function () {
                // 设置成功
            },
            fail:function(error){
              alert(JSON.stringify(error))
            }
          }
          wx.updateAppMessageShareData(dataShare)
          wx.updateTimelineShareData(dataShare)
          wx.error(function(error) {
              alert(JSON.stringify(error))
          })
        }else{
          Toast('configJssdk error')
        }
      })
    }
  }
}